package cn.mw.controller;

import cn.mw.domain.Menu;
import cn.mw.dto.MenuDto;
import cn.mw.dto.OrdDto;
import cn.mw.service.IOrderService;
import cn.mw.util.AjaxResult;
import cn.mw.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    /**
     * 下单
     * @return
     */
    @PostMapping("/order")
    public AjaxResult payment(@RequestBody OrdDto dto){
        try {
            orderService.payment(dto);
            return new AjaxResult().setResultObj("请求成功");
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return new AjaxResult().setResultObj("请求失败");
        }
    }

    /**
     * 订单查询
     * @return
     */
    @GetMapping("/getOrderByUserId/{userId}")
    public AjaxResult getOrderByUserId(@PathVariable("userId") Long userId){
        try {
            OrderVo vo = orderService.getOrderByUserId(userId);
            return new AjaxResult().setResultObj(vo);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return new AjaxResult().setResultObj("请求失败");
        }
    }
    /**
     * 订单查询
     * @return
     */
    @PostMapping("/addMenu")
    public AjaxResult addMenu(@RequestBody List<Menu> menus){
        try {
            orderService.addMenu(menus);
            return new AjaxResult().setResultObj("请求成功");
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return new AjaxResult().setResultObj("请求失败");
        }
    }
}
